#include <stdio.h>


//////////////////////////////////////
#define DEBUG_TRACE_LEVEL	DEBUG_MSG_LEVEL_OFF

enum debug_msg_level {
	DEBUG_MSG_LEVEL_OFF     = 0,
	DEBUG_MSG_LEVEL_ERROR,
	DEBUG_MSG_LEVEL_WARNING,
	DEBUG_MSG_LEVEL_INFO,
	DEBUG_MSG_LEVEL_VERBOSE,
	DEBUG_MSG_LEVEL_DEBUG,
	DEBUG_MSG_LEVEL_MAX
};

#undef  trace_dbg
#define trace_dbg(level, msg...) do { \
		if((level) >= DEBUG_TRACE_LEVEL) { \
			printf("\033[0;31m file:%s,Func:%s,Line:%d\033[0;39m\n",__FILE__, __FUNCTION__, __LINE__);\
			printf(msg); \
			printf("\n"); \
		} \
	}while(0)


//////////////////////////////////////
#define HIETH_TRACE_LEVEL	1

#define LEVEL_1		1
#define LEVEL_2		2
#define LEVEL_3		3
#define LEVEL_4		4
#define LEVEL_5		5
#define LEVEL_6		6
#define LEVEL_7		7
#define LEVEL_8		8


#define xiaozhi_dbg(level, msg...) do { \
		if((level) >= HIETH_TRACE_LEVEL) { \
			printf("\t[%s : %s : %d] ", __FILE__,__FUNCTION__, __LINE__); \
			printf(msg); \
			printf("\n"); \
		} \
	}while(0)


#define dbg(msg...) do { \
			printk("\t[%s : %d] ", __FUNCTION__, __LINE__); \
			printk(msg); \
			printk("\n"); \
		} while (0)


#define prk_dbg()	printf("%6s%13s%13d\n", "", __FUNCTION__, __LINE__);


#define pre_dbg()	printf("%6s%13s%13s%13s\n", "","filename", "function", "line");\
					printf("%6s%13s%13s%13d\n", "", __FILE__, __FUNCTION__, __LINE__);


/* for application */
#define xiaozhi_DEBUG		4
#define xiaozhi_INFO		3
#define xiaozhi_ERR		2
#define xiaozhi_FATAL		1

#define xiaozhi_DBG_LEVEL  	4

#define xiaozhi_trace(level, s, params...) do{ if(level <= xiaozhi_DBG_LEVEL)\
	printf("[%s, %d]: " s "\n", __FUNCTION__, __LINE__, ##params);\
}while(0)


/* for kernel */
#define HI_MCC_DEBUG		4
#define HI_MCC_INFO		3
#define HI_MCC_ERR		2
#define HI_MCC_FATAL		1
#define HI_MCC_DBG_LEVEL  	2
#define hi_mcc_trace(level, s, params...) do{ if(level <= HI_MCC_DBG_LEVEL)\
	printk(KERN_INFO "[%s, %d]: " s "\n", __FUNCTION__, __LINE__, ##params);\
}while(0)

/* for kernel */
#define PCIE_DEBUG_LEVEL_REG    1
#define PCIE_DEBUG_LEVEL_FUNC   2
#define PCIE_DEBUG_LEVEL_MODULE 3

#define PCIE_DEBUG_LEVEL PCIE_DEBUG_LEVEL_MODULE

#define PCIE_DEBUG
#ifdef PCIE_DEBUG
#define pcie_debug(level, str, arg...)\
	do {\
		if ((level) <= PCIE_DEBUG_LEVEL) {\
			printk(KERN_DEBUG "%s->%d," str "\n", \
					__func__, __LINE__, ##arg);\
		} \
	} while (0)
#else
#define pcie_debug(level, str, arg...)
#endif

/* for kernel */
#define pcie_assert(con)\
	do {\
		if (!(con)) {\
			printk(KERN_ERR "%s->%d,assert fail!\n", \
					__func__, __LINE__);\
		} \
	} while (0)

/* for kernel */
#define pcie_error(str, arg...)\
	do {\
		printk(KERN_ERR "%s->%d" str "\n", __func__, __LINE__, ##arg);\
	} while (0)


/* 带颜红色打印 */
#define PCIV_CHECK_ERR(err)\
do{\
    if(err!=0)\
    {\
        printf("\033[0;31m程序名err:%x,Func:%s,Line:%d\033[0;39m\n",err,__FUNCTION__,__LINE__);\
        return err;\
    }\
}while(0)


int main()
{
	int mode = 99;

	xiaozhi_dbg(LEVEL_3, "unsupport mode = %d", mode);
	pre_dbg();

	if (mode) {
		xiaozhi_trace(xiaozhi_ERR, "handle is not open");
	}

	if (mode != 98)
		xiaozhi_trace(xiaozhi_INFO, "poll not empty handle 0x%08lx",
									(unsigned long)mode);

//	return 0;
}

